<meta charset="UTF-8">
<?php

require ('./lib/init.php');//初始化
$cat_id = $_GET['cat_id'];
//检测栏目是否合法
if (!is_numeric($cat_id)){
    error ('栏目不合法');
    exit();
}
//检测栏目是否存在
$sql = "select count(*) from cat where cat_id = $cat_id";
$rs = mQuery($sql);
if (mysqli_fetch_row($rs)[0] == 0){
    error ('栏目不存在');
    exit();
}
//检测栏目是否存在文章
$sql = "select count(*) from art where cat_id = $cat_id";
$rs =  mQuery($sql);
$rs = mysqli_fetch_row($rs);
if ($rs[0] != 0){
    error ('栏目下存在文章');
    exit();
}

//检测完毕 删除栏目
$sql = "delete from cat where cat_id = $cat_id";
if (!mQuery($sql)){
    error ('删除失败');
}else{
    succ ('删除成功');
}
?>
